<template>
<div class="container">
  <div class="contacts">
    <h2>联系人列表</h2>
    <ul>
      <li>
        <img src="../assets/default_avatar.svg" alt="">
        <p>masaikk</p>
      </li>
      <li>
        <img src="../assets/default_avatar.svg" alt="">
        <p>noshira</p>
      </li>
    </ul>
  </div>
  
  <div class="chat">
    <div class="title">{{whoIChat}}</div>
    <div class="chat-box">
      <div v-for="item in messageList" :key="item.id" class="message" :class="item.sendOrReceive">
        {{item.content}}
      </div>
    </div>
    <div class="input-box">
      <input type="text" placeholder="请输入消息">
    </div>
  </div>
</div>
</template>


<script setup>
import { reactive } from 'vue';
const whoIChat = reactive('masaikk');
const messageList = reactive([{
    id: '0',
    content: '你好，最近怎么样？',
    type: 'text',
    isRead: true,
    sendOrReceive: 'send',
    timestamp: 1679239299000,
},
{
    id: '1',
    content: '我很好，谢谢。你呢？',
    type: 'text',
    isRead: true,
    sendOrReceive: 'receive',
    timestamp: 1679249299000,
},{
    id: '2',
    content: '我也很好。',
    type: 'text',
    isRead: true,
    sendOrReceive: 'send',
    timestamp: 1679259299000,
}])
</script>

<style scoped>
.container {
  display: flex;
  justify-content: space-between;
}

.contacts {
  width: 200px;
  height: 500px;
  background-color: #f5f5f5;
  padding: 20px;
}

.contacts h2 {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 10px;
}

.contacts ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.contacts li {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  cursor: pointer;
}

.contacts img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  margin-right: 10px;
}

.chat {
  height: 500px;
  width: 700px;
  background-color: #fff;
  padding: 20px 0 20px 20px;
  box-sizing: border-box;
  border: 1px solid #f5f5f5;
}

.chat .title {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 10px;
}

.chat-box {
  height: 400px;
  overflow-y: scroll;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.message {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  padding: 10px;
  border-radius: 10px;
  font-size: 14px;
}

.message p {
  width: 100%;
  margin: 0;
}

.receive {
  background-color: #f5f5f5;
  /* justify-content: flex-start; */
}

.send {
  background-color: #d9edf7;
  /* justify-content: flex-end; */
}

.input-box {
  display: flex;
  align-items: center;
}

.input-box input {
  flex: 1;
  height: 30px;
  border-radius: 5px;
  border: 1px solid #ccc; 
  padding: 5px 10px; 
}


</style>
